﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FacebookWrapper;
using FacebookWrapper.ObjectModel;

namespace C12_Ex02_Shaked_032675316_Itay_032511057
{
    public partial class WallMessagePoster : UserControl
    {
        private User m_User;
        private bool m_FileSelected;
        private string m_PicturePath;

        public event UserRelatedAction Post;

        public WallMessagePoster()
        {
            m_FileSelected = false;
            InitializeComponent();
        }

        public WallMessagePoster(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        private void ButtonPost_Click(object sender, EventArgs e)
        {
            m_User.PostStatus(TextBoxMessage.Text);
            TextBoxMessage.Text = string.Empty;
            OnPost();
        }

        public void OnPost()
        {
            if (Post != null)
            {
                Post.Invoke(m_User);
            }
        }

        public User User
        {
            get { return m_User; }
            set { m_User = value; }
        }

        private void buttonSelect_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Filter = "Picture Files (*.jpg; *.png; *.gif) | *.jpg; *.png; *.gif";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                m_FileSelected = true;
                m_PicturePath = fileDialog.FileName;
                labelPath.Text = fileDialog.FileName;
            }
        }

        private void buttonUpload_Click(object sender, EventArgs e)
        {
            if (m_FileSelected)
            {
                User.PostPhoto(m_PicturePath, textboxPictureDescription.Text);
                m_FileSelected = false;
                m_PicturePath = string.Empty;
                labelPath.Text = string.Empty;
                OnPost();
            }
            else
            {
                MessageBox.Show("You must select a picture to upload first!");
            }
        }
    }
}
